home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / B_INITVA.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  14KB  |  476 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*          This module was originally written by Vince Perriello           */
  13. /*                                                                          */
  14. /*                   BinkleyTerm Variable Initialization                    */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. void compile_externs (void);
  49. void fillin_defaults (struct secure *, struct secure *);
  50.  
  51. /**
  52.  ** b_initvars -- called before parse_config. Sets defaults that we want
  53.  ** to have set FIRST.
  54.  **/
  55.  
  56. void 
  57. b_initvars ()
  58. {
  59.     int k;
  60.     BINK_EVENT far *p;
  61.  
  62. #ifndef UCT_DIFFERENTIAL                /* if defined, don't kludge TZ */
  63.  
  64.     char *envp;
  65.  
  66.     if ((envp = getenv ("TZ")) != NULL)
  67.     {
  68.         if ((saved_TZ = calloc (1, 4 + strlen (envp))) != NULL)
  69.         {
  70.             (void) strcpy (saved_TZ, "TZ=");
  71.             (void) strcat (saved_TZ, envp);
  72.         }
  73.     }
  74.     (void) putenv ("TZ=GMT0");
  75. #endif
  76.  
  77.     tzset ();
  78.  
  79.     p = (BINK_EVENT far *) _fmalloc (256 * sizeof (BINK_EVENT));
  80.     if (p == (BINK_EVENT far *) NULL)
  81.     {
  82.         (void) printf (MSG_TXT (M_BAD_EVENT_ALLOC));
  83.         exit (252);
  84.     }
  85.  
  86.     e_ptrs = p;
  87.  
  88.     memset ((char *)p, 0, 256 * sizeof (BINK_EVENT));
  89.  
  90.     (void) memset ((char *) &DEFAULT, 0, sizeof (DEFAULT));
  91.  
  92.     KNOWN = DEFAULT;                    /* Does some of the work      */
  93.     KNOWN.rq_Limit = -1;
  94.     KNOWN.byte_Limit = -1L;
  95.     KNOWN.time_Limit = -1;
  96.     KNOWN.rq_Cum_Limit = -1;
  97.     KNOWN.byte_Cum_Limit = -1L;
  98.     KNOWN.time_Cum_Limit = -1L;
  99.     KNOWN.security = -1;
  100.  
  101.     PROT = KNOWN;                        /* Initially the same default */
  102.  
  103.     for (k = 0; k < 10; k++)            /* Zero the phone scan list   */
  104.     {
  105.         scan_list[k] = NULL;
  106.     }
  107.  
  108.     for (k = 0; k < MAX_EXTERN; k++)    /* And the external protocols */
  109.     {
  110.         protocols[k] = NULL;
  111.     }
  112.  
  113.     for (k = 1; k < ALIAS_CNT; k++)        /* And the alias list         */
  114.     {
  115.         alias[k].Zone = alias[k].Net = alias[k].Node = alias[k].Point = 0;
  116.         alias[k].Domain = NULL;
  117.     }
  118.  
  119.     alias[0].Zone = 1;                    /* Make sure we have a zone   */
  120.     alias[0].Net = alias[0].Node = (unsigned short) -1;    /* Default Fidonet address */
  121.     alias[0].Point = 0;
  122.     alias[0].Domain = NULL;
  123.  
  124. #ifdef Snoop
  125.     pipename[0] = '\0';                    /* Make sure we have no name  */
  126.     if (getenv ("SNOOPPIPE") != NULL)
  127.     {
  128.         strcpy (pipename, getenv ("SNOOPPIPE"));
  129.         snoop_open (pipename);
  130.     }
  131. #endif
  132.  
  133.     b_init ();
  134.  
  135.     baud = 2;
  136.     cur_baud = pbtypes[baud];
  137.     command_line_un = 0;
  138.  
  139.     (void) memset (&dta_str, 0, sizeof (dta_str));
  140.  
  141. #ifdef SET_CONMODE
  142.     setmode (fileno (stdin), O_BINARY);
  143.     setmode (fileno (stdout), O_BINARY);
  144. #endif
  145. }
  146.  
  147.  
  148. /**
  149.  ** b_defaultvars -- called after all parse_config passes complete.
  150.  ** sets anything not handled by parse_config to default if we know it.
  151.  **/
  152.  
  153. void 
  154. b_defaultvars ()
  155. {
  156.     int i;
  157.     char *p;
  158.  
  159.     if (!fullscreen)
  160.         do_screen_blank = 0;
  161.  
  162.     if (version7)
  163.         nodelist_name = "NODEX";
  164.     else
  165.         nodelist_name = "NODELIST";
  166.  
  167.     if (BBSopt == NULL)
  168. #ifdef BBS_SPAWN
  169.         BBSopt = ctl_string ("spawn");
  170. #else
  171.         BBSopt = ctl_string ("none");
  172. #endif
  173.  
  174.     if (modem_init == NULL)
  175.         modem_init = ctl_string ("|AT|");
  176.     if (modem_busy == NULL)
  177.         modem_busy = ctl_string ("|AT|");
  178.  
  179.     if (net_info == NULL)
  180.         net_info = ctl_string (".\\");
  181.  
  182.     /* Initialize the modem response strings if user didn't */
  183.  
  184.     if (mdm_resps == NULL)
  185.     {
  186.         mdm_resps = def_mdm_resps;
  187.         resp_count = max_resp_count = def_resp_count;
  188.     }
  189.  
  190.     /* Initialize session-level no-WaZOO and no-EMSI flags */
  191.  
  192.     no_WaZOO_Session = no_WaZOO;
  193.     no_EMSI_Session = no_EMSI;
  194.  
  195.     /* Set up "boss" and "point" addresses correctly if we can */
  196.  
  197.     if (boss_addr.Zone == 0)
  198.         boss_addr.Zone = alias[0].Zone;
  199.  
  200.     if (boss_addr.Net == 0)
  201.     {
  202.         boss_addr = alias[0];
  203.         boss_addr.Point = 0;
  204.     }
  205.  
  206.     if ((pvtnet >= 0) && (alias[0].Point != 0))
  207.     {
  208.         my_addr = boss_addr;
  209.         my_addr.Point = alias[0].Point;
  210.         alias[0].Net = (unsigned) pvtnet;
  211.         alias[0].Node = alias[0].Point;
  212.         alias[0].Point = 0;
  213.     }
  214.     else
  215.         my_addr = alias[0];
  216.  
  217.     /* If we have the minimum information to do netmail, set the flag */
  218.  
  219.     if ((alias[0].Zone != 0)
  220.         && (alias[0].Net != 0)
  221.         && (system_name != NULL)
  222.         && (sysop != NULL)
  223.         && (hold_area != NULL)
  224.         && (DEFAULT.sc_Inbound != NULL))
  225.     {
  226.         net_params = 1;
  227.         (void) flag_file (INITIALIZE, &alias[0], 0);
  228.     }
  229.  
  230.     if (system_name == NULL)
  231.         system_name = "";
  232.  
  233.     if (hold_area == NULL)
  234.         hold_area = ctl_string (".\\");
  235.  
  236.     if (flag_dir == NULL)        /* MB 93-12-12  PKTRSP  disable pktrsp if no flag directory */
  237.         pktrsp = 0;
  238.  
  239.     if (DEFAULT.sc_Inbound == NULL)
  240.         DEFAULT.sc_Inbound = ctl_string (".\\");
  241.  
  242.     /* Make the "higher class" requests at least as well off as the
  243.         "lowest class"... */
  244.  
  245.     fillin_defaults (&KNOWN, &DEFAULT);
  246.     fillin_defaults (&PROT, &KNOWN);
  247.  
  248.     if (extern_index)
  249.         compile_externs ();                /* generate extern_protocols  */
  250.  
  251.     if (!colors.calling && colors.hold)
  252.         colors.calling = (unsigned char) (((colors.hold & 0x70) >> 4) | ((colors.hold & 0x7) << 4) | (colors.hold & 0x8));
  253.  
  254.     if ((!colors.popup) && colors.call)
  255.         colors.popup = colors.call;
  256.  
  257.     first_block = 0;
  258.  
  259.     /* Make our domain first in the list */
  260.  
  261.     if (my_addr.Domain != NULL)
  262.     {
  263.         for (i = 0; domain_name[i] != NULL; i++)
  264.         {
  265.             if (domain_name[i] == my_addr.Domain)
  266.                 break;
  267.         }
  268.  
  269.         if ((i > 0) && (domain_name[i] == my_addr.Domain))
  270.         {
  271.             p = domain_name[0];
  272.             domain_name[0] = domain_name[i];
  273.             domain_name[i] = p;
  274.             p = domain_nodelist[0];
  275.             domain_nodelist[0] = domain_nodelist[i];
  276.             domain_nodelist[i] = p;
  277.             p = domain_abbrev[0];
  278.             domain_abbrev[0] = domain_abbrev[i];
  279.             domain_abbrev[i] = p;
  280.         }
  281.     }
  282.  
  283.     set_prior (4);                            /* Always High    */
  284.  
  285.     if (Cominit (port_ptr, buftmo) != 0x1954)
  286.     {
  287.         (void) printf (MSG_TXT (M_DRIVER_DEAD_1));
  288.         (void) printf (MSG_TXT (M_DRIVER_DEAD_2));
  289.         (void) printf (MSG_TXT (M_DRIVER_DEAD_3));
  290.  
  291.         set_prior (2);                        /* Regular        */
  292.         exit (1);
  293.     }
  294.  
  295.     i = un_attended;
  296.     un_attended = 0;
  297.  
  298.     (void) set_baud (max_baud.rate_value, 0);
  299.     un_attended = i;
  300.  
  301.     MDM_ENABLE (lock_baud && (pbtypes[baud].rate_value >= lock_baud) ? max_baud.rate_mask : pbtypes[baud].rate_mask);
  302.     RAISE_DTR ();
  303.     XON_ENABLE ();
  304.  
  305.     set_prior (2);                            /* Regular        */
  306.  
  307.     Txbuf = Secbuf = (byte *) calloc (1, WAZOOMAX + 16);
  308.     if (!Txbuf)
  309.     {
  310.         status_line (MSG_TXT (M_MEM_ERROR));
  311.         exit (2);
  312.     }
  313.  
  314. /*
  315.  * Pointing it to the middle of the buffer allows us to pop up
  316.  * file transfer windows if we choose to do so.
  317.  */
  318.  
  319.     popbuf = Secbuf + 1500;
  320.  
  321. /*
  322.  * Do a couple of system-related things.
  323.  * Maybe they shouldn't be here -- but better here than in BT.C.
  324.  *
  325.  * Because of some config verbs that affect its behavior, mtask_find
  326.  * MUST follow parse_config!
  327.  */
  328.  
  329.     fossil_ver ();
  330.     mtask_find ();
  331.  
  332. }
  333.  
  334. void 
  335. compile_externs ()
  336. {
  337.     register char *c;
  338.     register i;
  339.     char rgchT[100];
  340.     int j, k, l;
  341.     char *p;
  342.     char x;
  343.  
  344.     i = l = 0;                                    /* start at beginning     */
  345.     rgchT[0] = '\0';
  346.  
  347.     for (k = 0; protocols[k] != NULL; k++)        /* Total no. of protos    */
  348.     {
  349.         c = protocols[k];                        /* Point at filename      */
  350.         if (!dexists (c))                        /* Is it there?           */
  351.         {
  352.             (void) printf ("%s %s\n", MSG_TXT (M_NO_PROTOCOL), c);
  353.             continue;
  354.         }
  355.         p = NULL;
  356.         while (*c)                                /* Until end of string    */
  357.         {
  358.             if ((*c == '\\') || (*c == ':'))    /* Look for last path     */
  359.                 p = c;                            /* Delimiter              */
  360.             c++;
  361.         }
  362.         if (strlen (p) < 3)                        /* If no name,            */
  363.             continue;                            /* No protocol...         */
  364.  
  365.         p++;                                    /* Point to the           */
  366.         x = (char) toupper (*p);                /* First character        */
  367.         if (strchr (rgchT, x) != NULL)
  368.         {
  369.             (void) printf ("%s %s\n", MSG_TXT (M_DUP_PROTOCOL), c);
  370.             continue;
  371.         }
  372.  
  373.         protos[l].first_char = x;                /* Makes lookup fast      */
  374.         protos[l++].entry = k;                    /* Now we know where      */
  375.  
  376.         rgchT[i++] = x;                            /* Store first char       */
  377.         rgchT[i++] = ')';                        /* Then a ')'             */
  378.         c = ++p;                                /* Point to 2nd char      */
  379.         for (j = 0; j < 9; j++)                    /* Up to 9 chars more     */
  380.         {
  381.             if (*c != '.')                        /* If no comma yet,       */
  382.             {
  383.                 rgchT[i++] = (char) tolower (*c);/* store the char and    */
  384.                 ++c;                            /* bump the pointer       */
  385.             }
  386.             else
  387.                 rgchT[i++] = ' ';                /* otherwise pad it       */
  388.         }
  389.         rgchT[i++] = ' ';                        /* And one more space     */
  390.         rgchT[i] = '\0';                        /* Need for testing       */
  391.     }
  392.  
  393.     if (!i)                                        /* If we got none,        */
  394.         return;                                    /* Return now.            */
  395.  
  396.     i += 2;                                        /* Total for malloc       */
  397.     if ((extern_protocols = calloc (1, (unsigned) i)) == NULL)
  398.         return;                                    /* Return on failure      */
  399.     (void) strcpy (extern_protocols, rgchT);    /* Copy the string        */
  400.     return;                                        /* Back to caller         */
  401. }
  402.  
  403. void 
  404. fillin_defaults (struct secure *higher, struct secure *lower)
  405. {
  406.     if (higher->time_Limit == -1)
  407.         higher->time_Limit = lower->time_Limit;
  408.     if (higher->byte_Limit == -1L)
  409.         higher->byte_Limit = lower->byte_Limit;
  410.     if (higher->rq_Limit == -1)
  411.         higher->rq_Limit = lower->rq_Limit;
  412.  
  413.     if (higher->time_Cum_Limit == -1)
  414.         higher->time_Cum_Limit = lower->time_Cum_Limit;
  415.     if (higher->byte_Cum_Limit == -1L)
  416.         higher->byte_Cum_Limit = lower->byte_Cum_Limit;
  417.     if (higher->rq_Cum_Limit == -1)
  418.         higher->rq_Cum_Limit = lower->rq_Cum_Limit;
  419.     if (higher->security == -1)
  420.         higher->security = lower->security;
  421.  
  422.     if (higher->rq_FILES == NULL)
  423.         higher->rq_FILES = lower->rq_FILES;
  424.     if (higher->rq_OKFile == NULL)
  425.         higher->rq_OKFile = lower->rq_OKFile;
  426.     if (higher->rq_About == NULL)
  427.         higher->rq_About = lower->rq_About;
  428.     if (higher->rq_Template == NULL)
  429.         higher->rq_Template = lower->rq_Template;
  430.     if (higher->sc_Inbound == NULL)
  431.         higher->sc_Inbound = lower->sc_Inbound;
  432. }
  433.  
  434. /**
  435.  ** b_exitproc -- called by mainline to do exit processing.
  436.  **/
  437.  
  438. void 
  439. b_exitproc ()
  440. {
  441.     if (command_line_un)
  442.     {
  443.         mdm_init (modem_busy);
  444.         exit_DTR ();
  445.     }
  446.  
  447.     vfossil_cursor (1);
  448.  
  449.     while (KEYPRESS ())
  450.     {
  451.         (void) FOSSIL_CHAR ();
  452.     }
  453.  
  454.     gotoxy (0, SB_ROWS);
  455.     clear_eol ();
  456.     (void) printf (MSG_TXT (M_THANKS), ANNOUNCE);
  457.     clear_eol ();
  458.     (void) printf (MSG_TXT (M_ANOTHER_FINE_PRODUCT));
  459.  
  460.     if (vfossil_installed)
  461.         vfossil_close ();
  462.  
  463. #ifdef SET_CONMODE
  464.     setmode (fileno (stdin), O_TEXT);
  465.     setmode (fileno (stdout), O_TEXT);
  466. #endif
  467.  
  468.     if (!share)
  469.     {
  470.         set_prior (4);                        /* Always High */
  471.         MDM_DISABLE ();
  472.         set_prior (2);                        /* Regular */
  473.     }
  474. }
  475.  
  476.